//
//  MyCourseViewController.m
//  ZHIDOU
//
//  Created by 向礼 on 2018/12/18.
//  Copyright © 2018 向礼. All rights reserved.
//


#import "MyCourseViewController.h"
#import "MyCourseCell.h"
#import "MyCourseHeaderView.h"
#import "CourseDetailsViewController.h"
#import "FLBNavgationController.h"
#import "chooseGrade.h"

@interface MyCourseViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong)UITableView *tableView;

@property (nonatomic ,strong)MyCourseHeaderView *HeaderView;

///数据源
@property (nonatomic ,strong)NSMutableArray *dataSource;
@end

@implementation MyCourseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatRight];
    [self setUpViews];
    // Do any additional setup after loading the view.
}

#pragma mark - nav右边的导航栏
- (void)creatRight{
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 54, 20)];
    UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 20)];
    [myButton setTitle:@"七年级" forState:UIControlStateNormal];
    [myButton addTarget:self action:@selector(clickEvent) forControlEvents:UIControlEventTouchUpInside];
    [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [rightView addSubview:myButton];
      UIBarButtonItem *rightCunstomButtonView = [[UIBarButtonItem alloc] initWithCustomView:rightView];
    UIImageView *JiaoBiao = [[UIImageView alloc]initWithFrame:CGRectMake(50, 16, 4, 4)];
    JiaoBiao.image = [UIImage imageNamed:@"nav_grade_drop-down"];
    [rightView addSubview:JiaoBiao];
    self.navigationItem.rightBarButtonItem = rightCunstomButtonView;
}


#pragma mark - UI
- (void)setUpViews {
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, ZD_screenHeight) style:UITableViewStylePlain];
    self.tableView.separatorStyle = UITableViewCellEditingStyleNone;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableViewselectionStyle = UITableViewCellSelectionStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"MyCourseCell" bundle:nil] forCellReuseIdentifier:@"MyCourseCell"];
    self.tableView.tableHeaderView = self.HeaderView;
    [self.view addSubview:self.tableView];
}

-(void)clickEvent{
//    chooseGrade *grade = [[chooseGrade alloc]initWithFrame:CGRectMake(0, 0, ZD_screenWidth, ZD_screenHeight - self.bottomSafeAreaInsets)];
//    [self.view addSubview:grade];
    [chooseGrade showAlter:self];
}

#pragma mark - lazy

- (MyCourseHeaderView *)HeaderView {
    if (!_HeaderView) {
        _HeaderView = [[MyCourseHeaderView alloc] initWithFrame:CGRectMake(0, 0, ZD_screenWidth, 141)];
       // _HeaderView.delegate = self;
    }
    return _HeaderView;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCourseCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCourseCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //    cell.delegate = self;
    //    cell.productModel = self.model.productList[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 124;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CourseDetailsViewController *detail = [[CourseDetailsViewController alloc]init];
    [self.navigationController pushViewController:detail animated:YES];
}

@end
